package com.shop.base.impl;


import java.sql.Connection;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.util.List;
import java.util.logging.Logger;

import javax.sql.DataSource;

import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

import com.shop.base.dao.BaseDao;

/**
 * 数据逻辑层
 */
public abstract class BaseDaoImpl  implements BaseDao {
    
	private JdbcTemplate template;  
    
	private DataSource dataSource;
	public DataSource getDataSource() {
		return dataSource;
	}

	public void setDataSource(DataSource dataSource) {
		this.dataSource = dataSource;
	}

	/**
	 * 数据表名 
	 */
	private String tableName;
	
	private String tabNamePerfix = "db_";
	
	public String getTabNamePerfix() {
		return tabNamePerfix;
	}

	public void setTabNamePerfix(String tabNamePerfix) {
		this.tabNamePerfix = tabNamePerfix;
	}

	public BaseDaoImpl (String tableName) {
		
		this.tableName = tableName;
	}
	
    public String getTableName() {
		return tableName;
	}

	public void setTableName(String tableName) {
		this.tableName = tableName;
	}

	protected abstract Class<?> type();  //反射方法调用类 
    
    public JdbcTemplate getTemplate() {  
        return template;  
    }  
    
    public void setTemplate(JdbcTemplate template) {  
        this.template = template;  
    } 
    
    /**
     * @see BaseDao 
     */
    @SuppressWarnings("unchecked")
	public List<String> getCoulumByDataBase ()
    {
    	this.setTemplate(new JdbcTemplate(this.dataSource));
    	String sql = "select  column_name, column_comment  from Information_schema.columns  where table_Name = '"+this.tabNamePerfix+this.tableName+"'";
    	
		@SuppressWarnings("rawtypes")
		List<String> list = this.template.query(sql, new BeanPropertyRowMapper(this.type()));
    	
		return list;
		
    	
    }
}
